import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**
* class ClientWriteThread
*   - receive player moving actions from keyboard input
*   - create message packaged and deliver to server
*/
public class ClientWriteThread extends Thread {
	private PrintWriter os;
	
	public ClientWriteThread() {
		
	}
	 
	public void run() {
		boolean running = true;
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		try {
			String input = "";
			String request = "";
			while (running) {
				input = stdin.readLine();
				while (input != null) {
					// use A(west) D(east) W(north) S(south) N(nomove) to control
					if (input.equals("A") || input.equals("a")) {
						request = "move west";
						os.println(request);
						os.flush();
					}
					else if (input.equals("D") || input.equals("d")) {
						request = "move east";
						os.println(request);
						os.flush();
					}
					else if (input.equals("W") || input.equals("w")) {
						request = "move north";
						os.println(request);
						os.flush();
					}
					else if (input.equals("S") || input.equals("s")) {
						request = "move south";
						os.println(request);
						os.flush();
					}
					else if (input.equals("N") || input.equals("n")) { // nomove
						request = "move nomove";
						os.println(request);
						os.flush();
					}
					else {
						System.err.println("Invalid Instruction");
					}
					// waiting for command input
					input = stdin.readLine();
				}
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void setOS(PrintWriter os) {
		this.os = os;
	}
}
